import { Injectable } from '@nestjs/common';
import { UserService } from '../../user/user.service';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from '../../user/entities/user.entity';
import { Repository } from 'typeorm';

@Injectable()
export class SocketService {
  constructor(private userService: UserService) {}
  async create(socket) {
    // user: Partial<User>
    // const socketUser = await this.socketRepository.findOne({
    //   where: { userId: createSocketDto.userId },
    // });
    // if (socketUser) {
    //   // @ts-ignore
    //   this.update(Number(socketUser.id), createSocketDto);
    // } else {
    //   const tempSocket = await this.socketRepository.create(createSocketDto);
    //   return this.socketRepository.save(tempSocket);
    // }
    // const user = await this.userService.findOne(+socket.user);
    // console.log('user', user);
    // const tempFriend = await this.socketRepository.create(socket);
    // tempFriend.user = [user];
    // return this.socketRepository.save(tempFriend);
  }

  async getFriendByCode(code: string) {
    // return await this.socketRepository.findOne({ where: { code } });
  }
  findAll() {
    return `This action returns all socket`;
  }

  findOne(id: number) {
    // const fri = this.userService.findFriend(id);
    // return fri;
    return 'findOne  sock 111';
  }

  update(id: number, updateSocketDto) {
    // return this.socketRepository.update(id, updateSocketDto);
    return '123';
  }

  remove(id: number) {
    return `This action removes a #${id} socket`;
  }
}
